
$(function () {
	var UserInfo;
	(function() {
		UserInfo = JSON.parse(sessionStorage.getItem('UserInfo'));
		if(UserInfo){
			$(".noUser").addClass("disabledNone");
			$("#userInfo").removeClass("disabledNone");
			//加载判断头部
			$("#accunt").text(UserInfo.nickName||UserInfo.userName);
			sessionStorage.setItem('UserId',UserInfo.userId);
			$("#attestation").removeClass("disabledNone");
			if(UserInfo.proveType == -2){
			  $("#attestation").find("a").text("认证驳回");
			  $("#attestation").find("a").css("color","red");
			}else if(UserInfo.proveType == -1){
			  $("#attestation").find("a").text("认证审核中");
			}else if(UserInfo.proveType == 0){
			  $("#attestation").find("a").text("未认证");
			}else{
			  $("#attestation").find("a").text("已认证");
			  $("#attestation").find("a").css("color","lightgreen");
			}
		}else{
			$("#userInfo").addClass("disabledNone");
			$(".noUser").removeClass("disabledNone");
		}


	}());

	// $("#userInfo").click(function(){
	// 	window.location.href = './login.html';
	// })
	//跳转认证
	$("#attestation").click(function(){
		// 认证时需要传参reProve 1：新认证 2：重新认证
		if (UserInfo && UserInfo.proveType>0){
			window.sessionStorage.setItem('reProve',2)
		} else {
			window.sessionStorage.setItem('reProve',1)
		}
		window.location.href = './authentication.html';
	})
	//顶部搜索
	$(".searchKeyword").click(function () {
		window.location.href = "./dataSearch.html"
	})

	// 产品袋登录验证
	$('.myBtn').click(function () {
		$.ajax({
       timeout:30000,
			type: 'GET',
			url: window.Http + "/getInfo",
			headers: {
				'Authorization': "Bearer " + sessionStorage.getItem('Token')
			},
			success: function (res) {
				if (res.code == 200) {
					layer.open({
						type: 2,
						title: '产品袋',
						area: ['540px', '700px'],
						content: './mycart.html'
					})
				} else if (res.code == 401) {
					layer.alert('未登录，请前往登录界面进行登录', {
						skin: 'layui-layer-lan',
						closeBtn: 0,
						anim: 1 //动画类型
					}, function () {
						window.location.href = './login.html';
					});
				}
			}
		})
	})

	//退出登录
	$('#logOutBtn').click(function(e){
		e.preventDefault();
		layer.confirm('是否确认退出当前登录账号?', {icon: 3, title:'提示'}, function(index){
		  //请求退出登录接口
		  $.ajax({
       timeout:30000,
		  	url: window.Http + "/logout",
		  	type: 'POST',
		  	headers: {
		  		'Authorization': "Bearer " + sessionStorage.getItem('Token')
		  	},
		  	success: function (res) {
		  		if(res.code == 200){
		  			layer.msg("退出成功", {icon: 1});
					sessionStorage.setItem('Token',"");
					sessionStorage.setItem('UserId',"");
		  			setTimeout(function(){
						window.location.href = './login.html';
					},1000)
		  		}else{
		  			layer.msg(res.msg);
		  		}
		  	}
		  })
		  layer.close(index);
		});
	})

})
